<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="系统订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入原始系统订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信订单号" prop="transactionId">
        <el-input
          v-model="queryParams.transactionId"
          placeholder="请输入原始微信订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退款申请时间" prop="applicationTime">
        <el-date-picker clearable
                        v-model="queryParams.applicationTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择退款申请时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="退款完成时间" prop="completionTime">
        <el-date-picker clearable
                        v-model="queryParams.completionTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择退款完成时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="用户电话" prop="userContact">
        <el-input
          v-model="queryParams.userContact"
          placeholder="请输入申请用户电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column label="原始系统订单号" align="center" prop="orderNo" />
      <el-table-column label="原始微信订单号" align="center" prop="transactionId" />
      <el-table-column label="订单类型" align="center" prop="orderType" >
        <template slot-scope="scope">
          <el-tag  v-if="scope.row.orderType=='C'">课程</el-tag>
          <el-tag type="success" v-if="scope.row.orderType=='T'">桌台</el-tag>
          <el-tag type="info" v-if="scope.row.orderType=='G'">商品</el-tag>
          <el-tag type="warning" v-if="scope.row.orderType=='V'">VIP会员</el-tag>
          <el-tag type="danger" v-if="scope.row.orderType=='J'">教练入住</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="原始金额" align="center" prop="transactionAmount" />
      <el-table-column label="退款金额" align="center" prop="refundAmount" />
      <el-table-column label="申请用户id" align="center" prop="userId" />
      <el-table-column label="申请用户电话" align="center" prop="userContact" />
      <el-table-column label="用户姓名" align="center" prop="userName" />
      <el-table-column label="退款状态" align="center" prop="refundStatus" >
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.refundStatus=='Refunded '">已支付</el-tag>
          <el-tag type="warning" v-if="scope.row.refundStatus=='NoRefunded'">待支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="退款申请时间" align="center" prop="applicationTime" width="180"/>
      <el-table-column label="退款完成时间" align="center" prop="completionTime" width="180"/>
      <el-table-column label="创建时间" align="center" prop="createAt" width="180"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:record:edit']"
          >退款</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecord} from "@/api/debao/record";

export default {
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退款订单表格数据
      recordList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        transactionId: null,
        orderType: null,
        createAt: null,
        applicationTime: null,
        completionTime: null,
        transactionAmount: null,
        refundAmount: null,
        userId: null,
        userContact: null,
        userName: null,
        refundStatus: null
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询退款订单列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('debao/record/export', {
        ...this.queryParams
      }, `record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
